package ChainOfResponsibility;

public class ChainOfResponsibilityDemo {

    private static AbstractLogger getChainOfLoggers(){
        // 全部转化成 父类型.
        AbstractLogger consoleLogger = new ConsoleLogger(AbstractLogger.INFO);  // 1
        AbstractLogger errorLogger = new ErrorLogger(AbstractLogger.ERROR);  // 3
        AbstractLogger fileLogger = new FileLogger(AbstractLogger.DEBUG);  // 2

        // error -> file -> console  3 2 1
        errorLogger.setNextLogger(fileLogger);
        fileLogger.setNextLogger(consoleLogger);

        return errorLogger; // 把链式的头返回去
    }


    public static void main(String[] args){
        AbstractLogger chainLoggers = ChainOfResponsibilityDemo.getChainOfLoggers();

        chainLoggers.logMessage(AbstractLogger.INFO, "This is an information with level:" + AbstractLogger.INFO);
        System.out.println(" --- ");
        chainLoggers.logMessage(AbstractLogger.DEBUG, "This is an Debug msg with level: " + AbstractLogger.DEBUG);
        System.out.println(" --- ");
        chainLoggers.logMessage(AbstractLogger.ERROR, "This is an Error msg with level: " + AbstractLogger.ERROR);
    }
}
